home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / gopher / Unix / xgopher.1.3 / sc_index.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-08  |  4.4 KB  |  195 lines

  1. /* sc_index.c
  2.    gopher item subclass procedures for index search result directories */
  3.  
  4.      /*---------------------------------------------------------------*/
  5.      /* Xgopher        version 1.3     08 April 1993                  */
  6.      /*                version 1.2     20 November 1992               */
  7.      /*                version 1.1     20 April 1992                  */
  8.      /*                version 1.0     04 March 1992                  */
  9.      /* X window system client for the University of Minnesota        */
  10.      /*                                Internet Gopher System.        */
  11.      /* Allan Tuchman, University of Illinois at Urbana-Champaign     */
  12.      /*                Computing and Communications Services Office   */
  13.      /* Copyright 1992, 1993 by                                       */
  14.      /*           the Board of Trustees of the University of Illinois */
  15.      /* Permission is granted to freely copy and redistribute this    */
  16.      /* software with the copyright notice intact.                    */
  17.      /*---------------------------------------------------------------*/
  18.  
  19. #include "conf.h"
  20. #include "globals.h"
  21. #include "gopher.h"
  22. #include "util.h"
  23. #include "status.h"
  24. #include "appres.h"
  25. #include "item.h"
  26. #include "dir.h"
  27. #include "gui.h"
  28. #include "sc_index.h"
  29. #include "sc_indexP.h"
  30.  
  31.  
  32. /* getIndexDirectory
  33.    load a new gopher directory resulting from an index search */
  34.  
  35. BOOLEAN
  36. getIndexDirectory(gi, string)
  37. gopherItemP    gi;
  38. char        *string;
  39. {
  40.     int        s;
  41.     gopherDirP    d;
  42.     BOOLEAN        fetchOK;
  43.  
  44.     if (( s = GI_connectWithStatus(gi) ) < 0 ) return FALSE;
  45.  
  46.     writeString(s, vStringValue(&(gi->selector)));
  47.  
  48.     /* if string is NULL, then the search string is already encoded in
  49.        the selector */
  50.  
  51.     if (string != NULL) {
  52.         writen(s, "\t", 1);
  53.         writeString(s, string);
  54.     }
  55.  
  56.     writeString(s, EOL_STRING);
  57.  
  58.     d = newDir();
  59.  
  60.     showStatus("Awaiting search results",
  61.             noCurrentDir() ? STAT_ROOT : STAT_DIRECTORY,
  62.             gi->host, gi->port);
  63.  
  64.     fetchOK = GI_getGopherDir(s, d);
  65.  
  66.     close(s);
  67.  
  68.     if (!removeStatusPanel() ) {
  69.  
  70.         /* someone cancelled as the directory load finished */
  71.  
  72.         freeDir(d);
  73.         return FALSE;
  74.     }
  75.  
  76.     if (! fetchOK) {
  77.  
  78.         /* failure to load directory */
  79.  
  80.         freeDir(d);
  81.         showError(
  82.             "There are no files selected by this index search\n");
  83.         return FALSE;
  84.     }
  85.  
  86.     setDirTime(d);
  87.  
  88.     d->selectorItem = copyItem(gi);
  89.     if (string != NULL) {
  90.         char    indexPath[PATH_NAME_LEN + INDEX_WORD_LEN];
  91.  
  92.         strcpy(indexPath, vStringValue(&(gi->selector)));
  93.         strcat(indexPath, "\t");
  94.         strcat(indexPath, string);
  95.         vStringSet(&(d->selectorItem->selector), indexPath);
  96.     }
  97.  
  98.     if (string != NULL) {
  99. #define            INDEX_LABEL " - Index words: "
  100.         char    *title = USER_STRING(d->selectorItem);
  101.         int    len=strlen(title);
  102.         int    remaining = USER_STRING_LEN - len;
  103.         int    labelLen = strlen(INDEX_LABEL);
  104.  
  105.         title += len;
  106.         strncpy(title, INDEX_LABEL, remaining);
  107.         remaining -= labelLen;
  108.         title += labelLen;
  109.         strncpy(title, string, remaining);
  110.     }
  111.     
  112.     pushCurrentDir(d);
  113.  
  114.     displayCurrent();
  115.  
  116.     return TRUE;
  117. }
  118.  
  119.  
  120. /* processIndexSelection
  121.    process the index transaction from the user's selected keyword string */
  122.  
  123. void
  124. processIndexSelection(gi, string)
  125. gopherItemP    gi;
  126. char        *string;
  127. {
  128.     /* this function is similar to a "getDirectory" operation */
  129.  
  130.  
  131.     getIndexDirectory(gi, string);
  132. }
  133.  
  134.  
  135. /* GIIndex_process
  136.    process an index search selection */
  137.  
  138. BOOLEAN
  139. GIIndex_process(gi)
  140. gopherItemP    gi;
  141. {
  142.     BOOLEAN    result;
  143.     char *ind = getItemIndex(gi);
  144.  
  145.     if (ind == NULL) {
  146.  
  147.         /* normal case: no search string previously
  148.            selected.  Display panel; after string is selected,
  149.            it is passed to processIndexSelection. */
  150.  
  151.  
  152.         /* This call will put up the panel with a grabNone, so
  153.            that other gopher activity can proceed.  This could
  154.            be slightly confusing, but allows help text panels to
  155.            be popped up/down from the index search request panel.
  156.            Any action will result in a callback that eventually
  157.            invokes processIndexSelection. */
  158.         
  159.         showIndex(gi);
  160.  
  161.     } else {
  162.         /* if bookmark index search string is already stored
  163.            in the gopher item.  No need to prompt for it. */
  164.  
  165.         result = getIndexDirectory(gi, NULL);
  166.     }
  167.  
  168.  
  169.     return result;
  170. }
  171.  
  172.  
  173. /* GIIndex_init
  174.    initialize index directory class - prefix string */
  175.  
  176. void
  177. GIIndex_init()
  178. {
  179.     GU_makePrefix(prefixIndex,  appResources->prefixIndex);
  180.     GU_registerNewType(A_INDEX, &indexSubclass);
  181.  
  182.     return;
  183. }
  184.  
  185.  
  186. /* GIIndex_restart
  187.    clean up index subclass for a restart request */
  188.  
  189. void
  190. GIIndex_restart()
  191. {
  192.     removeIndexPanel();
  193.     return;
  194. }
  195.